package com.songsong.myblog2.controller;

import com.songsong.myblog2.service.UserService;
import net.sf.json.JSONObject;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/users")
public class UsersController {

    /*注入userService*/
    @Autowired
    private UserService userService;
    /*
     * 跳转到编写博客页面
     * */
    @RequestMapping("/editor")
    public String editor() {
        return "anon/editor";
    }

    /*
     * 跳转到我的相册页面
     * */
    @RequestMapping("/share")
    public String share() {
        return "authc/share";
    }

    /*
     * 跳转个人中心
     * */
    @RequestMapping("/user")
    public String user() {
        return "anon/user";
    }

    /*
     * 跳转管理员页面
     * */
    @RequestMapping("/admin")
    @RequiresRoles(value = "admin")
    public String admin() {
        return "anon/superadmin";
    }

    /**
     * 管理员获取用户管理
     *
     * @return
     */

    @GetMapping("/getUserManagement")
    @ResponseBody
    @RequiresRoles(value = "admin")
    public JSONObject getUserManagement(@RequestParam("rows") String rows,
                                           @RequestParam("pageNum") String pageNum) {
        return userService.getUserManagement(Integer.parseInt(rows), Integer.parseInt(pageNum));
    }

}
